package org.yjhking.controller;

import org.springframework.web.bind.annotation.*;
import org.yjhking.dto.Movie;
import org.yjhking.query.AjaxResult;
import org.yjhking.service.MovieTicketService;

import javax.annotation.Resource;

/**
 * @author YJH
 */
@RestController
public class MovieController {
    @Resource
    private MovieTicketService movieTicketService;
    
    /**
     * 查询所有电影票
     */
    @GetMapping
    public AjaxResult getMovieList() {
        return movieTicketService.getMovieList();
    }
    
    /**
     * 根据电影票id购买电影票
     *
     * @param movie 电影票id 用户id
     */
    @PostMapping("/buy")
    public AjaxResult buy(@RequestBody Movie movie) {
        return movieTicketService.buy(movie);
    }
    
    /**
     * 根据电影票id查询用户是否有此电影票
     *
     * @param movie 电影票id 用户id
     */
    @PostMapping
    public AjaxResult selectByMovieId(@RequestBody Movie movie) {
        return movieTicketService.selectByMovieId(movie);
    }
    
    @GetMapping("/free/{id}")
    public AjaxResult free(@PathVariable Long id) {
        return movieTicketService.free(id);
    }
    
    @PostMapping("/watch")
    public AjaxResult watchMovie(@RequestBody Movie movie) {
        return movieTicketService.watchMovie(movie);
    }
}
